﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using CE.AreaCountry;
using CE.Global;
using CE.TravelInsurance;

public partial class Provider_TravelInsurance_ViewProviderTIPremium : System.Web.UI.Page
{
    string PageName = "CXTI";
    string SubPageName = "CXTIPRM";
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Session[CE.Global.General.UserId] == null || Session[CE.Global.General.ProviderCompanyId] == null)
        {
            Response.Redirect("~/Provider/ProviderSecureLogin.aspx");
        }
        CheckMainPageAccess();
        CheckSubPageAccess();

        if (!Page.IsPostBack)
        {
            LoadRegion();

            ddlPlanName.Items.Insert(0, new ListItem("Select", "-1"));
        }

        lnkNewClaimInfo.NavigateUrl = "~/Provider/TravelInsurance/ProviderTIPremium.aspx?TID=" + lblTAId.Text;

    }

    private void LoadRegion()
    {
        DataTable _dtRegion = General.GetComboItem("RegionArea", true);
        ddlAreaRegion.DataSource = _dtRegion;
        ddlAreaRegion.DataTextField = _dtRegion.Columns[0].ColumnName.ToString();
        ddlAreaRegion.DataValueField = _dtRegion.Columns[1].ColumnName.ToString();
        ddlAreaRegion.DataBind();

        ddlAreaRegion.Items.Insert(0, new ListItem("Select", "-1"));
    }

    protected void LoadPremium(object sender, EventArgs e)
    {
        TAQuoteResultDB _tadb = new TAQuoteResultDB();
        TAQuoteResult _tadetails = new TAQuoteResult();

        //_tadetails = _tadb.GetTASelectSingleItemSelected(Convert.ToInt64(Session[CE.Global.General.ProviderCompanyId].ToString()), ddlPolicyType.SelectedValue.ToString(), ddlLevelOfCoverage.SelectedValue.ToString());
        DataTable _dtPremium = new DataTable();

        if (ddlPlanName.SelectedIndex > 0)
        {
            _tadetails = _tadb.GetTAQuoteResult(Convert.ToInt64(ddlPlanName.SelectedValue), ddlPolicyType.SelectedValue.ToString());

            if (_tadetails != null)
            {
                //lblPlanName.Text = _tadetails.PlanName;
                lblTAId.Text = _tadetails.TAInsId.ToString();

                CE.Provider.TAPremiumDB _tapremiumdb = new CE.Provider.TAPremiumDB();
                
                _dtPremium = _tapremiumdb.GetPremiumDTList(Convert.ToInt64(Session[CE.Global.General.ProviderCompanyId].ToString()), ddlPolicyType.SelectedValue.ToString(), Convert.ToInt64(lblTAId.Text), Convert.ToInt64(ddlAreaRegion.SelectedValue.ToString()));
                             
            }

        }

        grvPremium.DataSource = _dtPremium;
        grvPremium.DataBind();
       
      

    }

    protected void GetPlans(object sender, EventArgs e)
    {
        DataTable dtPlans = new DataTable();
        TAQuoteResultDB _tadb = new TAQuoteResultDB();

        dtPlans = _tadb.GetTASelectSingleItemSelectedDT(Convert.ToInt64(Session[CE.Global.General.ProviderCompanyId].ToString()), ddlPolicyType.SelectedValue);

        if (dtPlans.Rows.Count > 0)
        {
            ddlPlanName.DataSource = dtPlans;
            ddlPlanName.DataTextField = "PlanName";
            ddlPlanName.DataValueField = "TAInsId";
            ddlPlanName.DataBind();
        }
        else
        {
            ddlPlanName.Items.Clear();
        }

        ddlPlanName.Items.Insert(0, new ListItem("Select", "-1"));

        this.LoadPremium(this, null);

    }

    protected void ibtBack_Click(object sender, ImageClickEventArgs e)
    {
        Response.Redirect("~/Provider/TravelInsurance/TravelInsuranceHome.aspx");
    }

    private void CheckMainPageAccess()
    {
        Int64 PageAccess = General.GetProviderMainPageAccess(Convert.ToInt64(Session[General.ProviderCompanyId].ToString()),
                                                        Convert.ToInt64(Session[General.UserId].ToString()), PageName);
        if (PageAccess == 0)
        {
            //Response.Redirect("~/Provider/UserMessage.aspx?errorcode=2000");
            Response.Redirect("~/Provider/UserMessage.aspx?mt=UM&ec=2000");
        }
    }

    private void CheckSubPageAccess()
    {
        Int64 PageAccess = General.GetProviderSubPageAccess(Convert.ToInt64(Session[General.ProviderCompanyId].ToString()),
                                                        Convert.ToInt64(Session[General.UserId].ToString()), SubPageName);
        if (PageAccess == 0)
        {
            //Response.Redirect("~/Provider/UserMessage.aspx?errorcode=2000");
            Response.Redirect("~/Provider/UserMessage.aspx?mt=UM&ec=2000");
        }
        else if (PageAccess == 100)
        {
            lnkNewClaimInfo.Visible = false;
        }
    }


}
